﻿using DefCore;
using DefCore.Tools;
using DefCore.Mapping;
using DefCore.Structures;
using Ivory;
using Krypton;
using Krypton.Lights;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DefCore.Core;
using DefCore.Interfaces;

namespace Defender.Framework.Structures
{
    public sealed class WoodBridgeBlueprint : Blueprint
    {
        //fields

        //ctor
        public WoodBridgeBlueprint()
            : base(new Vector2(184, 184), BlueprintFrameType.FULLFRAME)
        {

        }

        //Methods
        protected override void RenderBlueprint(SpriteBatch batch, GameTime time)
        {
            batch.Draw(StructureBin.Instance.GetStructure("BRIDGE_WOOD", true), (Rectangle)HitRect, Color.White);
        }

        public override bool ValidatePlacement(CellBase cell)
        {
            return (cell is WaterCell) || (cell is LavaCell);
        }
        public override Structure CreateStructure(CellBase cell, StructureFrameEnum frame)
        {
            return StructureFactory.Create<WoodBridge>(cell, frame);
        }
    }

    public sealed class WoodBridge : Structure
    {        
        //Fields

        //ctor
        public WoodBridge(CellBase cell, StructureFrameEnum frame)
            : base(cell, StructureType.Passive, frame)
        {
            this.MaxHealth = 5;            
        }
         
        //Methods
        public override void OnGlobalTick(object sender, GlobalTickEventArgs e)
        {
            if (ParentCell is LavaCell)
                this.Damage(2);
        }


        protected override void OnCreate()
        {
            if (ParentCell is WaterCell)
                (ParentCell as WaterCell).StructureAllowsWalking = true;
            if (ParentCell is LavaCell)
                (ParentCell as LavaCell).StructureAllowsWalking = true;
        }
        protected override void OnDelete()
        {
            if (ParentCell is WaterCell)
                (ParentCell as WaterCell).StructureAllowsWalking = false;
            if (ParentCell is LavaCell)
                (ParentCell as LavaCell).StructureAllowsWalking = false;
        }
        
        public override void Render(SpriteBatch batch, GameTime time)
        {
            batch.Draw(StructureBin.Instance.GetStructure("BRIDGE_WOOD", false), HitBox, Color.White);
        }
        public override void Solve(InputControl control, GameTime time)
        {
        }        
    }
}
